# -*- coding: utf-8 -*-
import itertools
def readp():
    f = open("prime.txt")
    l = f.readlines()
    f.close

    result = []
    for stra in l:
        a = stra.split(' ')
        result = map(int,a)
    return result

primes = readp()
sums = []
def chazhao():

    p673 = []
    for x in primes[0:110]:
        if x < 110:
            p673.append(x)

    p673.append(673)
    print p673

    pr4 = itertools.combinations(p673,4)

    for a,b,c,d in pr4:
##        print a,b,c,d
        if jisuan(a,b,c,d):
            break

    print min(sums)
def qiuhe(a,b,c,d):
    f = a + b + c +d
    return f

def jisuan(a,b,c,d):
    global sums
    stra = str(a)
    strb = str(b)
    strc = str(c)
    strd = str(d)

    strabcd = [stra,strb,strc,strd]

    pr2 = itertools.permutations(strabcd,2)
    for aa,bb in pr2:
##        print a+b
        if int(aa+bb) not in primes:
##            print u"不在素数范围"
            return 0
    print u'符合要求:',a,b,c,d,a+b+c+d
    sums.append(qiuhe(a,b,c,d))
    return 1

def main():
    chazhao()

if __name__ == '__main__':
    import time
    start = time.time()
    main()
    print('Execution time: {0} seconds'.format(time.time() - start))
